/*
 * SignHistoryPresenter.java
 * business
 *
 * Created by ChenTao on 2017/6/30.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.signhistory;

import com.yidiandao.business.data.model.ISignModel;
import com.yidiandao.business.data.model.SignModel;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.view.SuperLoadingLayout;

import java.util.List;

/** 抽奖记录 */
public class SignHistoryPresenter implements SignHistoryContract.Presenter {

    private final ISignModel mModel;
    private SignHistoryContract.View mView;

    public SignHistoryPresenter(SignHistoryContract.View view) {
        mView = view;
        mView.setPresenter(this);
        mModel = new SignModel();
    }

    @Override
    public void start() {
        getSignHistory(true);
    }

    @Override
    public void getSignHistory(final boolean isRefresh) {
        mModel.getRaffleRecord(
                mView.getPagerTag(),
                isRefresh,
                new ISignModel.onLoadRecordListener() {
                    @Override
                    public void onSuccess(
                            List<DisplayListItem> listItems,
                            String count,
                            boolean emptyResult,
                            boolean hasMoreData) {
                        mView.setRecordCount(count);
                        if (isRefresh) {
                            mView.refreshContent(mView.checkResultObject(listItems));
                            mView.setRefreshComplete();
                        }
                        mView.loadMoreFinish(emptyResult, hasMoreData);
                        mView.setDisplayListItems(listItems);
                    }

                    @Override
                    public void onFailed() {
                        if (isRefresh) {
                            mView.refreshContent(SuperLoadingLayout.STATE_ERROR);
                        } else {
                            mView.loadMoreError();
                        }
                    }

                    @Override
                    public void onFinal() {
                    }
                });
    }
}
